package com.zhangzhan.utils;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 张一恒
 * @version 1.0
 */
public class BeanCopyUtils {

    private BeanCopyUtils(){

    }

    /**
     * copy工具类
     * @param source
     * @param pojo
     * @param <V>
     * @return
     */
    public static <V> V beanCopyUtils(Object source , Class<V> pojo){
        V result = null;
        try {
             result = pojo.newInstance();
            //copy
            BeanUtils.copyProperties(source,result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    public static <O,V> List<V> beanCopyUtil(List<O> list , Class<V> pojo){
        return list.stream()
                .map(o -> beanCopyUtils(o, pojo))
                .collect(Collectors.toList());
    }

}
